#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
    int x, y1, y2, y3, i = 0;
    scanf("%d %d %d %d", &x, &y1, &y2, &y3);

    while ((y1 + y2 + y3 + 2 * i) < x)
        i++;
    
    printf("%d", i);
    return 0;
}